from flask_login import UserMixin

from exts import db


class User(UserMixin,db.Model):
    __tabelname__ ='users'

    id = db.Column(db.Integer,primary_key=True,autoincrement=True)
    email = db.Column(db.String(64),index=True)
    username = db.Column(db.String(64),nullable=False,index=True)
    password = db.Column(db.String(128),nullable=False)
    role_id = db.Column(db.Integer,db.ForeignKey('roles.id'))

    role =db.relationship('Roles',backref='users')
    def __str__(self):
        return self.username


class Roles(db.Model):
    __tabelname__ = 'roles'
    id = db.Column(db.Integer,primary_key=True,autoincrement=True)
    name = db.Column(db.String(16),nullable=False)

    def __str__(self):
        return self.name